package com.xijia;

import com.xijia.proxy.jdk.JdkInvocationHandler;
import com.xijia.proxy.xijia.XiJiaInvocationHandler;
import com.xijia.service.OrderService;
import com.xijia.service.impl.OrderServiceImpl;


/**
 * jdk 动态代理
 */
public class Test {
    public static void main(String[] args) {
        useJdkInvocation();

        useXijiaInvocation();
    }


    /**
     * 使用jdk 的动态代理方法生成class文件并执行
     */
    public static void useJdkInvocation() {
        JdkInvocationHandler jdkInvocationHandler = new JdkInvocationHandler(new OrderServiceImpl());
        // 获取代理类对象
       // System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles", "true");
        OrderService proxy = jdkInvocationHandler.getProxy();
        String res = proxy.addOrder("12345689", "测试");
        System.out.println("返回数据为:" + res);
    }



    /**
     * 使用自定义的模仿的 jdk动态代理方法生成class文件并执行
     */
    public static void useXijiaInvocation() {
        System.out.println("===============================");
        XiJiaInvocationHandler xiJiaInvocationHandler = new XiJiaInvocationHandler(new OrderServiceImpl());
        OrderService proxy = xiJiaInvocationHandler.getProxy();
        String res = proxy.addOrder("12345689", "测试");
        System.out.println("返回数据为:" + res);
    }

}
